package com.exception;

import com.pr.exception.CustomCheckedException;
import com.pr.exception.CustomUncheckedException;

/**
 * @description:
 * @projectName:spring-skill
 * @see:com.exception
 * @author:LXC
 * @createTime:2024/9/28 12:41
 * @version:1.0
 */
public class ExceptionDemo {
    public void testCheckedException() throws CustomCheckedException {
        // 模拟抛出自定义的受检异常
        throw new CustomCheckedException("This is a custom checked exception");
    }

    public void testUncheckedException() {
        // 模拟抛出自定义的非受检异常
        throw new CustomUncheckedException("This is a custom unchecked exception");
    }

    public static void main(String[] args) {
        ExceptionDemo demo = new ExceptionDemo();
        try {
            while (true){
                demo.testCheckedException();
                Thread.sleep(1000);
            }
        } catch (CustomCheckedException | InterruptedException e) {
            System.out.println("Caught checked exception: " + e.getMessage());
        }

        demo.testUncheckedException();  // 不需要显式捕获
    }
}
